import myAxios from "@/plugins/myAxios";
import { showToast } from "vant";

//创建队伍
const createTeam = async (teamAddRequest) => {
  return await myAxios
    .post("/team/add", teamAddRequest)
    .then((res) => {
      return res;
    })
    .catch((error) => {
      showToast(error.message);
    });
};

//全量查询队伍
const queryTeam = async (teamQueryRequest) => {
  return await myAxios
    .get("/team/list", {
      params: teamQueryRequest,
    })
    .then((res) => res)
    .catch((error) => {
      showToast(error.message);
    });
};

//加入队伍
const joinTeam = async (teamJoinRequest) => {
  return await myAxios
    .post("/team/join", teamJoinRequest)
    .then((res) => res)
    .catch((error) => {
      showToast(error.message);
    });
};
//根据id查询队伍
const queryTeamById = async (id) => {
  return await myAxios
    .get("/team/get", {
      params: {
        id,
      },
    })
    .then((res) => res)
    .catch((error) => {
      showToast(error.message);
    });
};
//更新队伍
const updateTeam = async (teamUpdateRequest) => {
  return await myAxios
    .post("/team/update", teamUpdateRequest)
    .then((res) => res)
    .catch((error) => {
      showToast(error.message);
    });
};
//获取用户创建的队伍
const queryCreateTeam = async (teamQueryRequest) => {
  return await myAxios
    .get("/team/my/create", {
      params: teamQueryRequest,
    })
    .then((res) => res)
    .catch((error) => {
      showToast(error.message);
    });
};

//获取用户加入的队伍
const queryJoinTeam = async (teamQueryRequest) => {
  return await myAxios
    .get("/team/my/join", {
      params: teamQueryRequest,
    })
    .then((res) => res)
    .catch((error) => {
      showToast(error.message);
    });
};
//退出队伍
const quitTeam = async (teamId) => {
  return await myAxios
    .get("/team/quit", {
      params: {
        teamId,
      },
    })
    .then((res) => res)
    .catch((error) => {
      showToast(error.message);
    });
};
//解散队伍
const deleteTeam = async (id) => {
  return await myAxios
    .post("/team/delete", null, {
      params: {
        id,
      },
    })
    .then((res) => res)
    .catch((error) => {
      showToast(error.message);
    });
};

export {
  createTeam,
  queryTeam,
  joinTeam,
  queryTeamById,
  updateTeam,
  queryCreateTeam,
  queryJoinTeam,
  quitTeam,
  deleteTeam,
};
